<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>留言板 - 我的后台</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="__STATIC__/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="__CSS__/news.css" media="all" />
</head>
<body class="childrenBody">

	<div class="layui-form news_list">
		<div class="refresh">
			<div class="layui-btn-group">
				<a onclick="location.reload();" class="layui-btn layui-btn-primary"><i class="layui-icon">&#xe669;</i></a>
				<a onclick="history.back();" class="layui-btn layui-btn-primary"><i class="layui-icon">&#xe65c;</i></a>
			</div>
		</div>
			
		<table class="layui-hide" id="demo" lay-filter="demo"></table>
	</div>
	<script type="text/html" id="type-temp">
		{{#  if(d.type == 1){ }}
			<span>用户留言</span>
		{{#  } else if(d.type == 2) { }}
			<span>后台回复</span>
		{{#  } }}
	</script>

	<script type="text/html" id="reply-temp">
		{{#  if(d.isreply == -1){ }}
			<span>否</span>
		{{#  } else if(d.isreply == 1) { }}
			<span>是</span>
		{{#  } }}
	</script>

	<script type="text/html" id="status-temp">
		<input type="checkbox" name="status" value="{{d.message_id}}" lay-skin="switch" lay-text="显示|隐藏" lay-filter="statusDemo" {{ d.status == 1 ? 'checked' : '' }}>
	</script>

	<script type="text/html" id="barDemo">
		<a class="layui-btn layui-btn-xs" title="查看" lay-event="detail">详情</a>
		<a class="layui-btn layui-btn-xs layui-btn-danger" title="删除" lay-event="del">删除</a>
	</script>

	<script type="text/javascript" src="__STATIC__/layui/layui.js"></script>
	<script type="text/javascript">
		
		layui.use(['form', 'layer', 'table'],function(){
			var form  = layui.form,
				layer = layui.layer,
				table = layui.table,
				$ = layui.$;

				layer.msg("加载中...", {'time':1000});

				table.render({
					elem: '#demo'
					,page:true
					,url:'/admin/message/reply_list?type=1&message_id=<?php echo $message_id;?>'
					,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
					,cols: [[
						{field:'message_id', title: 'ID', width:100, sort: true}
						,{field:'nickname', title: '管理员', width:200}
						,{field:'type', title: '类型', width:150, templet:"#type-temp"}
						,{field:'create_time', title: '添加时间', width: 250, sort: true}
						,{fixed:'right', title: '操作',toolbar:"#barDemo", minWidth: 120}
					]]
				});	

		        //监听工具条
		        table.on('tool(demo)', function(obj){
		            var data     = obj.data,
		                layEvent = obj.event;
		            if(layEvent === 'detail') {
						var id   = data.message_id;
		            	layer.open({
		            		type:2,
		            		title:"查看留言",
		            		content: "/admin/message/read_message?message_id="+id,
		            		area: ['800px', '550px']
		            	})

		            }else if(layEvent === 'del'){
		                layer.confirm('确定删除？', function (index) {
		                    //向服务端发送删除指令
		                    var message_id = data.message_id;
		                    $.ajax({
		                        url: "/admin/message/delmessage",
		                        type: "POST",
		                        data: {"message_id": message_id},
		                        dataType: "json",
		                        success: function (data) {
		                            if (data.status == '1') {
		                                //删除这一行
		                                obj.del();
		                                //关闭弹框
		                                layer.close(index);
		                                layer.msg(data.msg, {icon: 6});
		                            } else {
		                                layer.msg(data.msg, {icon: 5});
		                            }
		                        }
		                    });
		                });
		            }
		        });

		})	
	</script>
</body>
</html>